<?php

namespace App\Http\Requests;

use Illuminate\Validation\Rule;

class GoodsListRequest extends BaseRequest {
    /**
     * Get the validation rules that apply to the request.
     * @return string[]
     */
    public function rules(): array
    {
        return [
            'categoryId' => 'integer|digits_between:1,20',
            'brandId' => 'integer|digits_between:1,20',
            'keyword' => 'string',
            'isNew' => 'boolean',
            'isHot' => 'boolean',
            'page' => 'integer',
            'limit' => 'integer',
            'sort' => Rule::in(['add_time', 'retail_price', 'name']),
            'order' => Rule::in(['desc', 'asc'])
        ];
    }

    public function messages(): array
    {
        return [
            'categoryId.integer' => '分类参数类型不正确',
            'categoryId.digits_between' => '分类参数不正确',
            'brandId.integer' => '品牌参数类型不正确',
            'brandId.digits_between' => '品牌参数不正确',
            'keyword.string' => '关键词参数不正确',
            'isNew.digits_between' => '新品参数不正确',
            'isHot.integer' => '热门参数不正确',
            'page.digits_between' => '页码不正确',
            'limit.digits_between' => '每页显示参数不正确',
            'sort.in' => '排序字段不正确',
            'order.in' => '排序方式不正确',
        ];
    }
}
